import config from './config';
// import constService from './services/const.js';
App({
  // $const: constService,
  userInfo: null,
  apiAccessToken: wx.getStorageSync('apiAccessToken'),
  sessionId: null,
  shareCode: null,
  backUrl: null,
  class: {},
  skuList: [],
  afterSalesSkuList: [], //售后商品列表
  onLaunch(options) {
    // 小程序自动更新提示
    const updateManager = wx.getUpdateManager()
    updateManager.onCheckForUpdate(function (res) {
      // 请求完新版本信息的回调
      console.log(res.hasUpdate)
    })
    updateManager.onUpdateReady(function () {
      setTimeout(() => {
        wx.showModal({
          title: '更新提示',
          content: '新版本已经准备好，是否重启应用？',
          success: function (res) {
            if (res.confirm) {
              // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
              updateManager.applyUpdate()
            }
          }
        })
      }, 2000);
    })
    //禁用短链分享
    wx.onCopyUrl(() => {
      setTimeout(() => {
        wx.setClipboardData({
          data: '暂不支持分享',
        })
      }, 500)
    })
    wx.getSystemInfo({
      success: res => {
        let scale = 750 / res.windowWidth;
        let safeHeight = parseInt((res.screenHeight - res.safeArea.bottom) * scale)
        this.systemInfo = {
          safeHeight,
          statusBarHeight: res.statusBarHeight,
          topNavHeight: res.statusBarHeight + 46,
          sheetHeight: parseInt((res.screenHeight - res.statusBarHeight - 46) * scale)
        }
      }
    });
  },
  onShow(options) {
    this.globalData.scene = options.scene
  },
  globalData: {
    userInfo: null,
    scene: -1,
  },
  getPrePage() {
    let pages = getCurrentPages()
    return pages[pages.length - 1]
  },
  isLogin() {
    console.log(this.apiAccessToken)
    if (this.apiAccessToken) return true
    wx.navigateTo({ url: '/pages/loginpage/loginpage' })
  },
})